package com.fbli.Thread.method;

public class ThreadMethod03 extends Thread{
    public static void main(String[] args) throws InterruptedException {
        MyDaemonThread myDaemonThread = new MyDaemonThread();
        //如果希望当main主线程结束后，子线程2自动结束
        //我们只需将子线程设为守护线程
        myDaemonThread.setDaemon(true);
        myDaemonThread.start();
        for (int i = 0; i < 10; i++) {
            System.out.println("宝强在幸苦的工作。。。");
            Thread.sleep(1000);
        }
    }
}
class MyDaemonThread extends Thread{
    @Override
    public void run() {
        for (;;){//无限循环
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("快乐聊天2333");
        }
    }
}